package com.gdut.simple.view.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.gdut.simple.R;
import com.gdut.simple.data.entity.PhotoFolder;
import com.gdut.simple.view.adapter.base.AbsRecyclerAdapter;
import com.gdut.simple.view.adapter.base.AbsViewHolder;
import com.squareup.picasso.Picasso;

import java.io.File;
import java.util.List;

public class PhotoFolderAdapter extends AbsRecyclerAdapter<PhotoFolder> {

    public PhotoFolderAdapter(Context context, List<PhotoFolder> list) {
        super(context, list);
    }

    @Override
    protected AbsViewHolder createHolder(ViewGroup parent, int viewType) {
        return new ItemViewHolder(mInflater.inflate(R.layout.layout_photo_spinner_item, parent, false));
    }

    @Override
    protected void showViewHolder(AbsViewHolder holder, int position) {
        ItemViewHolder viewHolder = (ItemViewHolder) holder;
        viewHolder.dir.setText(mData.get(position).getName());
        viewHolder.count.setText(mData.get(position).getCount() + "张");
        Picasso.with(mContext)
                .load(new File(mData.get(position).getFirstPhotoPath()))
                .placeholder(R.drawable.ic_place_holder)
                .error(R.drawable.ic_load_error)
                .config(Bitmap.Config.RGB_565)
                .into(viewHolder.image);
    }

    private static class ItemViewHolder extends AbsViewHolder {

        ImageView image;
        TextView dir;
        TextView count;

        ItemViewHolder(View itemView) {
            super(itemView);
            image = (ImageView) itemView.findViewById(R.id.id_spinner_image);
            dir = (TextView) itemView.findViewById(R.id.id_spinner_dir);
            count = (TextView) itemView.findViewById(R.id.id_spinner_count);
        }
    }
}
